#ifndef _YEP_MOUSE_EVENT_HPP
#define _YEP_MOUSE_EVENT_HPP

#include "../common.hpp"
#include "SystemEvent.hpp"
#include "../math/Vector2.hpp"

namespace yep
{
/**
 * @brief Handles mouse motion
 **/
class MouseMoveEvent: public SystemEvent
{
public:
	MouseMoveEvent(Game &game, Scene2d &scene, const Vector2 &oldPosition_,
			const Vector2 &newPosition_, Uint32 pressed) :
			SystemEvent(game, scene), oldPosition(oldPosition_), newPosition(
					newPosition_)
	{
		pressedButtons = pressed;
	}

	~MouseMoveEvent()
	{
	}

	/**
	 * @brief Returns the oldPosition
	 **/
	const Vector2 &getOldPosition(void) const
	{
		return oldPosition;
	}

	/**
	 * @brief Returns the newPosition
	 **/
	const Vector2 &getNewPosition(void) const
	{
		return newPosition;
	}

	/**
	 * @brief Returns the pressedButtons
	 **/
	Uint32 getPressedButtons(void) const
	{
		return pressedButtons;
	}

	SDL_Event getEvent() const
	{
		SDL_Event ev;
		ev.motion = (SDL_MouseMotionEvent) {SDL_MOUSEMOTION, 0, (Uint8)pressedButtons, (Uint16)newPosition.x, (Uint16)newPosition.y,
			(Sint16)(newPosition.x - oldPosition.x), (Sint16)(newPosition.y - oldPosition.y)};
		return ev;
	}

private:
	Vector2 oldPosition;
	Vector2 newPosition;
	Uint32 pressedButtons;
};

/**
 * @brief Handles a mouse button event
 **/
class MouseButtonEvent: public SystemEvent
{
public:
	MouseButtonEvent(Game &game, Scene2d &scene, const Vector2 &position_,
			Uint32 button_) :
			SystemEvent(game, scene), position(position_)
	{
		button = button_;
	}
	~MouseButtonEvent()
	{
	}

	/**
	 * @brief Returns the position
	 **/
	const Vector2 &getPosition(void) const
	{
		return position;
	}

	/**
	 * @brief Returns the button
	 **/
	Uint32 getButton(void) const
	{
		return button;
	}

	/**
	 * @brief Returns whether pressed.
	 * @return if pressed
	 */
	bool getPressed() const
	{
		return pressed;
	}

	SDL_Event getEvent() const
	{
		SDL_Event ev;
		ev.button = (SDL_MouseButtonEvent) {(Uint8)(pressed?SDL_MOUSEBUTTONDOWN:SDL_MOUSEBUTTONUP), 0, (Uint8)button, (Uint8)(pressed?SDL_PRESSED:SDL_RELEASED), (Uint16)position.x, (Uint16)position.y};
		return ev;
	}

private:
	Vector2 position;
	Uint32 button;
	bool pressed;
};

}

#endif // _YEP_MOUSE_EVENT_HPP
